                           let util = require('../../utils/util');
let that;

Page({
    data: {
        storeInfoList: []
    },
    onLoad: function() {
        that = this;
        let {storeId, storeName, storePhone, storeAdress, storeDescription, storeWecome, storeServiceOffLineMsg} = util.globalData('loginData').storeData;
        that.setData({storeInfoList: [
            {infoId: 'storeId', infoName: '店铺ID', infoVal: storeId, noedit: true},
            {infoId: 'storeName', infoName: '店铺名称', infoVal: storeName, noedit: true},
            {infoId: 'storePhone', infoName: '店铺电话', infoVal: storePhone, maxLength: 18},
            {infoId: 'storeAdress', infoName: '店铺地址', infoVal: storeAdress, maxLength: 80},
            {infoId: 'storeDescription', infoName: '店铺简介', infoVal: storeDescription, maxLength: 200},
            {infoId: 'storeWecome', infoName: '聊天欢迎语', infoVal: storeWecome, maxLength: 200},
            {infoId: 'storeServiceOffLineMsg', infoName: '离线回复语', infoVal: storeServiceOffLineMsg, maxLength: 200},
        ]});
    },
    onShow: function() {
        if(util.globalData('lastEditInfo')) {
            let {infoId, infoVal} = util.globalData('lastEditInfo');
            let {storeInfoList} = that.data;
            for(let infoIndex in storeInfoList) {
                if(storeInfoList[infoIndex].infoId == infoId) {
                    storeInfoList[infoIndex].infoVal = infoVal;
                    break;
                }
            }
            that.setData({storeInfoList: storeInfoList});
            util.globalData('lastEditInfo', null);
        }
    },
    editStoreInfo: function(e) {
        let storeInfoId = e.currentTarget.dataset.infoid;
        let storeInfoList = that.data.storeInfoList;
        for(let infoIndex in storeInfoList) {
            let {infoId, infoName, infoVal, maxLength, noedit} = storeInfoList[infoIndex]
            if(infoId == storeInfoId && !noedit) {
                wx.navigateTo({
                    url: '/pages/editStoreInfo/editStoreInfo?dataType=storeInfo&infoId=' + infoId + '&infoName=' + infoName + '&infoVal=' + infoVal + '&maxLength=' + maxLength,
                  fail: function(res) {
                    wx.showModal({
                        title: '跳转失败',
                        content: '跳转到编辑' + infoName + '页面失败'
                    });
                  }
                });
            }
        }
    },

    onPullDownRefresh: function() {
        let {storeId, storeName, storePhone, storeAdress, storeDescription, storeWecome, storeServiceOffLineMsg} = util.globalData('loginData').storeData;
        that.setData({
            storeInfoList: [
                { infoId: 'storeId', infoName: '店铺ID', infoVal: storeId, noedit: true },
                { infoId: 'storeName', infoName: '店铺名称', infoVal: storeName, noedit: true },
                { infoId: 'storePhone', infoName: '店铺电话', infoVal: storePhone, maxLength: 18 },
                { infoId: 'storeAdress', infoName: '店铺地址', infoVal: storeAdress, maxLength: 80 },
                { infoId: 'storeDescription', infoName: '店铺简介', infoVal: storeDescription, maxLength: 200 },
                { infoId: 'storeWecome', infoName: '聊天欢迎语', infoVal: storeWecome, maxLength: 200 },
                { infoId: 'storeServiceOffLineMsg', infoName: '离线回复语', infoVal: storeServiceOffLineMsg, maxLength: 200 },
            ]
        });
        wx.stopPullDownRefresh();
    }

});